/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
 * Description:
 * Author: g00421808
 * Create: 6/24/2022
 * Notes:
 */

#ifndef JSBIND_CLASS_H
#define JSBIND_CLASS_H

#include "class_base.h"
#include "jsbind/overloader/napi/napi_overloader.h"

namespace Jsb {
template <class C>
class Class : public ClassBase {
public:
    Class() = default;

    ~Class() = default;

    static Class<C>& GetInstance() {
        static Class<C> instance;
        return instance;
    }

    void AddConstructor(Binder* binder) {
        binder_ = binder;
        NapiOverloader::AddMethod(wrapperConstructorGroupId_,
                                  binder->GetArity(),
                                  binder->GetWrapper());

        NapiOverloader::AddMethod(valueConstructorGroupId_,
                                  binder->GetArity(),
                                  binder->GetValueConstructor());
    }

    const napi_ref* GetClassRefs() override {
        return ref_;
    }

    void SetClassRefs(napi_ref* originalRef) override {
        ref_ = originalRef;
    }

private:
    napi_ref* ref_;
};
} // namespace Jsb

#endif //JSBIND_CLASS_H
